<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<portlet:defineObjects/>

<fmt:setBundle basename="resources.contacts" scope="request"/>    

<jsp:include page="/WEB-INF/jsp/css.jsp"/>
<%@ include file="processActionException.jsp" %>
<jsp:include page="/WEB-INF/jsp/tabs.jsp"/>

<%@ include file="setBeans.jsp" %>    

<c:if test="${renderException == null}">
    <c:if test="${!empty prefsBean.userName}">
        <portlet:actionURL var="clearUserAction">
            <portlet:param name="action" value="clear-user"/>
        </portlet:actionURL>
        <table>
            <tr>
                <td class="<portlet:namespace/>-icon">
                    <img src="<c:out value="${myBean.buddyIconUrl}"/>"/>                    
                     </td>
                <td class="<portlet:namespace/>-left">
                    <fmt:message key="clearUser">
                        <fmt:param value="${prefsBean.userName}"/>
                        <fmt:param value="${pageScope['clearUserAction']}"/>
                    </fmt:message>                    
                </td>
            </tr>
        </table>
    </c:if>
    <c:if test="${!authHandler.authenticated}">
        <p><jsp:include page="auth.jsp"/></p>
    </c:if>    
    <c:if test="${empty prefsBean.userName}">
        <portlet:actionURL var="setUserNameAction">
            <portlet:param name="action" value="navigate-setUserName"/>
        </portlet:actionURL>
        <p>
            <fmt:message key="setUserName">
                <fmt:param value="${pageScope['setUserNameAction']}"/>
            </fmt:message>
        </p>
    </c:if>
    <c:if test="${authHandler.authenticated || !empty prefsBean.userName}">
        <portlet:actionURL var="selectContactAction"/>            
        <form name="selectContactForm" action="<%= selectContactAction%>" method="post" onChange="selectContactForm.submit()">
            <table>
                <tr>
                    <td class="<portlet:namespace/>-right">
                        Contact:                        
                    </td>
                    <td class="<portlet:namespace/>-left">
                        <input type="hidden" name="action" value="select-contact"/>
                        <select name="selectedContact">
                            <c:forEach var="contact" items="${contactsBean.contacts}">
                                <c:choose>
                                    <c:when test="${contact.nsId == contactsBean.selectedContact.nsId}">
                                        <option value="${contact.nsId}" selected><c:out value="${contact.userName}"/></option> 
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${contact.nsId}"><c:out value="${contact.userName}"/></option> 
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                        
                    </td>
                    <td>
                        <input type="submit" value="<fmt:message key="go"/>">                    
                           </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="<portlet:namespace/>-icon">
                        <img src="<c:out value="${contactsBean.selectedContactBuddyIconUrl}"/>"/>                        
                         </td>
                    <td>&nbsp;</td>
                </tr>
            </table>
        </form>
        <p><jsp:include page="photos.jsp"/></p>                      
    </c:if>
</c:if>
